
import { commonConstants } from 'hhlt-core/constants'
import { systemUtils} from 'hhlt-core/utils'
import { formatUtils,requestUtils} from 'hhlt-vue/utils'
import { IPageInfo} from 'hhlt-core/src/model/page/pageInfo'
import { IDataTablePager} from 'hhlt-core/src/model/page/dataTablePager'
import { VxeGridPropTypes, VxeTableDefines } from 'vxe-table'
import { IColumnInfo} from 'hhlt-core/src/model/form/column'
import { IExecuteData} from 'hhlt-core/src/model/base/resultModel'
import { FormRules } from 'element-plus'
import { fixedDatasource} from "hhlt-core/constants"
import { objectUtils } from 'hhlt-core/utils'
import { requestContextPath } from 'lxsh-cer-web-pc/src/constants'
import { ICerStaffImpro, ICerStaffImproQO, ICerStaffImproVO,CerStaffImpro } from 'lxsh-cer-web-pc/src/model/cer/cer/staff-impro/cer-staff-impro'
/**
* 员工通勤减碳业务实现
*/
export default {
//获取页面信息，根据不同的功能编码来加载不同的页面
getPageInfo:function(pageInfo:IPageInfo<ICerStaffImpro>){
  this.getColumnInfo()
},
/**
* 获取列信息
*/
getColumnInfo(successCallback?:(columnsParam:VxeGridPropTypes.Columns)=>void){
    var columns:VxeGridPropTypes.Columns = [
      { type: 'checkbox', width: 50 },
      { type: 'seq', width: 60,align:'center',title:'序号' },
      { field: 'id', title: '主键ID', visible:false },
      { field: 'factoryCode', title: '线体编码', showOverflow: true, sortable: true,width:'100px' },
      { field: 'workProcedureCode', title: '班组编码', showOverflow: true, sortable: true,width:'100px' },
      {field: 'commuteType', title: '通勤方式', showOverflow: true, sortable: true,width:'100px' },
      {field: 'commuteTypeDicName', title: '通勤方式',visible:false, showOverflow: true, sortable: true,width:'100px' },
      { field: 'startTime', title: '开始时间', formatter: formatUtils.formatDate, showOverflow: true, sortable: true ,width:'160px'},
      { field: 'endTime', title: '结束时间', formatter: formatUtils.formatDate, showOverflow: true, sortable: true ,width:'160px'},
      { field: 'totalMile', title: '时间范围内通勤总里程', showOverflow: true, sortable: true,width:'190px' },
      { field: 'otherAdvice', title: '其它改善建议', showOverflow: true, sortable: true,width:'130px' },
      { field: 'addUserName', title: '添加者名', showOverflow: true, sortable: true,width:'100px' },
      { field: 'addDate', title: '添加时间', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { title: '操作', width: 200, slots: { default: 'operate' },fixed:'right' }
    ];
    if(successCallback){
      successCallback(columns);
    }
  },
  /**
   * 获取检索条件
   */
  getSearchCondition(successCallback:(searchCondtionParam:IColumnInfo[],queryParams:ICerStaffImproQO) => void){
    var searchCondition = [
      { columnCode: 'factoryCode', columnName: '线体编码', basicControlType:commonConstants.enumBasicControlType.COMBOBOX,defaultValue:"",controlAttrValue:requestContextPath.basedata + '/basedata/factory/getComboList',controlNeedValue:'' },
      { columnCode: 'workProcedureCode', columnName: '班组编码', basicControlType:commonConstants.enumBasicControlType.COMBOBOX,defaultValue:"",controlAttrValue:requestContextPath.basedata + '/basedata/organization/getOrganizationCombList?modelType=50',controlNeedValue:'' },
      { columnCode: 'startTime', columnName: '开始时间', basicControlType:commonConstants.enumBasicControlType.DATE,defaultValue:"",controlAttrValue:"" },
      { columnCode: 'totalMile', columnName: '时间范围内通勤总里程', basicControlType:commonConstants.enumBasicControlType.TEXT_BOX,defaultValue:"",controlAttrValue:"" },
    ];
    var queryParam:ICerStaffImproQO = {
        id:undefined,
       /**
	    * factoryCode:线体编码
	    */
    factoryCode:"",
       /**
	    * workProcedureCode:班组编码
	    */
    workProcedureCode:"",
       /**
	    * startTime:开始时间
	    */
    startTime: undefined,
       /**
	    * totalMile:时间范围内通勤总里程
	    */
    totalMile: undefined,
    }
    return successCallback(searchCondition,queryParam);
  },
  /**
   * 单条删除操作
   */
  doDeleteSingle(selectItem:ICerStaffImproVO,successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/staffImpro/deleteByLogicBatch';
    let list = new Array();
    let item:ICerStaffImproQO = {
      id:selectItem.id
    }
    list.push(item)
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 单条删除操作
   */
  doDeleteBatch(selectList:ICerStaffImproVO[],successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/staffImpro/deleteByLogicBatch';
    let list = new Array();
    for (let selectItem of selectList) {
      let item :ICerStaffImproVO = {
        id:selectItem.id
      };
      list.push(item);
    }
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 获取分页数据
   */
  getListByPager(queryParam:ICerStaffImproQO,pager:IDataTablePager<ICerStaffImproVO>,successCallback?:(queryResult:IExecuteData<IDataTablePager<ICerStaffImproVO>>) => void):Promise<IExecuteData<IDataTablePager<ICerStaffImproVO>>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/staffImpro/getListByPager';
    return  requestUtils.getListByPager(url, queryParam, pager,successCallback)
  },
  addForm(formData:ICerStaffImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/staffImpro/insert";
    return requestUtils.insert(url, formData,successCallback);
  },
  updateForm(formData:ICerStaffImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/staffImpro/update";
    return requestUtils.update(url, formData,successCallback);
  },
  updateEnable(formData:ICerStaffImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/staffImpro/updateEnable";
    return requestUtils.update(url, formData,successCallback);
  },
  getInfoByCondition(param:ICerStaffImproQO,successCallback?:(result:IExecuteData<ICerStaffImproVO>) => void):Promise<IExecuteData<ICerStaffImproVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/staffImpro/getInfoByCondition";
    return requestUtils.getInfoByCondition(url, param,successCallback);
  },
  exportExcel(param:any,fileName:string,successCallback?:(result:IExecuteData<String>) => void):Promise<IExecuteData<String>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/staffImpro/exportExcel";
    const result:any = requestUtils.exportExcel(url, param,fileName,successCallback);
    if(result.success){
      if(successCallback){
        successCallback(result)
      }
    }
    return result;
  },
  //获取表单项
  getFormDataItem(successCallback:(formData:ICerStaffImpro,verify:FormRules) => void){
    var formData:ICerStaffImpro = new CerStaffImpro()
        // 校验
    var verify:FormRules = {
        factoryCode: [{
            required: true,
            message: "线体编码不能为空！"
        }],
        workProcedureCode: [{
            required: true,
            message: "班组编码不能为空！"
        }],
        commuteType: [{
            required: true,
            message: "通勤方式不能为空！"
        }],
        startTime: [{
            required: true,
            message: "开始时间不能为空！"
        }],
        endTime: [{
            required: true,
            message: "结束时间不能为空！"
        }],
        totalMile: [{
            required: true,
            message: "时间范围内通勤总里程不能为空！"
        }],
    }
    return successCallback(formData,verify)
  }
}
